package com.heima.model.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 通用的结果返回类
 */
@Data
public class ResponseResult<T> implements Serializable {

    private Integer code; //状态码 200 成功；500 错误
    private String errorMessage;//错误消息
    private T data;//响应数据
    private Long total;//分页时总条数

    public ResponseResult() {
    }

    public ResponseResult(Integer code, String errorMessage, T data, Long total) {
        this.code = code;
        this.errorMessage = errorMessage;
        this.data = data;
        this.total = total;
    }

    public static ResponseResult error(String errorMessage) {
        return new ResponseResult(500, errorMessage, null, null);
    }

    public static ResponseResult ok() {
        return new ResponseResult(200, null, null, null);
    }

    public static <T> ResponseResult ok(T data) {
        return new ResponseResult(200, null, data, null);
    }

    public static <T> ResponseResult ok(T data, Long total) {
        return new ResponseResult(200, null, data, total);
    }

}
